package com.adinnet.admin.system.service.impl;

import com.adinnet.admin.system.mapper.SysRoleMapper;
import com.adinnet.admin.system.model.SysRole;
import com.adinnet.admin.system.model.vo.SysUserInfo;
import com.adinnet.admin.system.service.SysRoleService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 角色表 服务实现类
 * </p>
 *
 * @author sunjianbo
 * @since 2019-05-17
 */
@Service
public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> implements SysRoleService {


    @Override
    public List<SysRole> getListByUserRole(SysUserInfo sysUserInfo) {
        QueryWrapper queryWrapper=new QueryWrapper();
        queryWrapper.eq("deleted",0);
        if(sysUserInfo!=null && sysUserInfo.getMaxRoleSerialNumber()!=null && sysUserInfo.getMaxRoleSerialNumber()>0){
            queryWrapper.ge("serial_number",sysUserInfo.getMaxRoleSerialNumber());
        }
        queryWrapper.orderByAsc("serial_number");
        return baseMapper.selectList(queryWrapper);
    }

    @Override
    public SysRole getRoleByRoleCode(String roleCode){
        QueryWrapper queryWrapper=new QueryWrapper();
        queryWrapper.eq("deleted",0);
        queryWrapper.eq("role_code",roleCode);
        return baseMapper.selectOne(queryWrapper);
    }
}
